package cn.edu.nbpt.campus_api.controller.campus;

import cn.edu.nbpt.campus_api.model.Page;
import cn.edu.nbpt.campus_api.model.Result;
import cn.edu.nbpt.campus_api.model.campus.entity.Clazz;
import cn.edu.nbpt.campus_api.model.campus.vo.ClassStudentVo;
import cn.edu.nbpt.campus_api.service.campus.ClassService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("campus/class")
public class ClassController {

    @Resource
    private ClassService classService;

    @GetMapping("list")
    public Result<Page<Clazz>> selectClassList(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String code,
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize
    ) {
        return Result.success(classService.selectClassList(name, code, pageNum, pageSize));
    }

    @GetMapping("{id}")
    public Result<Clazz> selectClass(
            @PathVariable Integer id
    ) {
        return Result.success(classService.selectClass(id));
    }

    @PostMapping
    public Result<Integer> insertClass(
            @RequestBody ClassStudentVo classStudentVo
    ) {
        return Result.success(classService.insertClass(classStudentVo));
    }

    @PutMapping
    public Result<Integer> updateClass(
            @RequestBody ClassStudentVo classStudentVo
    ) {
        return Result.success(classService.updateClass(classStudentVo));
    }

    @DeleteMapping("{ids}")
    public Result<Integer> deleteClass(
            @PathVariable List<Integer> ids
    ) {
        return Result.success(classService.deleteClass(ids));
    }
}
